#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "gtree.h"

void printf_data(GTreeData* data)
{
  printf("%c", data);
}

int main(int argc, char* argv[])
{
  GTree* gtree = GTree_Create();

  GTree_Insert(gtree, (GTreeData*)'A', -1);
  GTree_Insert(gtree, (GTreeData*)'B', 0);
  GTree_Insert(gtree, (GTreeData*)'C', 0);
  GTree_Insert(gtree, (GTreeData*)'D', 0);
  GTree_Insert(gtree, (GTreeData*)'E', 1);
  GTree_Insert(gtree, (GTreeData*)'F', 1);
  GTree_Insert(gtree, (GTreeData*)'H', 3);
  GTree_Insert(gtree, (GTreeData*)'I', 3);
  GTree_Insert(gtree, (GTreeData*)'J', 3);

  printf("FULL TREE:\n");

  GTree_Display(gtree, printf_data, 2, '-');

  printf("\n");
  // 验证get操作
  printf("Get Tree Data:\n");
  for(uint8_t i=0; i<GTree_Count(gtree); i++)
  { 
    printf_data(GTree_Get(gtree, i));
    printf("\n");
  }  

  printf("\n");
  printf("Tree Root Data:\n");
  printf_data(GTree_Root(gtree));

  printf("\n\n");
  printf("Tree's height:%d\n", GTree_Height(gtree));

  printf("\n");
  printf("Tree's degree:%d\n", GTree_Degree(gtree));

  printf("\n");
  printf("Tree's count:%d\n", GTree_Count(gtree));

  printf("\n");
#if 0
  GTree_Delete(gtree, 2);   // 第2个位置对应的是C

  printf("After Delete C:\n");

  GTree_Display(gtree, printf_data, 2, '-');

  GTree_Delete(gtree, 2);   // 第2个位置对应的是D

  printf("After Delete D:\n");

  GTree_Display(gtree, printf_data, 2, '-');
#else
  GTree_Clear(gtree);

  printf("After Clear:\n");

  GTree_Display(gtree, printf_data, 2, '-');
#endif

  GTree_Destroy(gtree);
  return 0;
}